package check;

import javax.swing.*;
import javax.swing.table.TableCellRenderer;
import java.awt.*;

public class CheckBoxRenderer extends JCheckBox implements TableCellRenderer {
    public CheckBoxRenderer() {
        setHorizontalAlignment(SwingConstants.CENTER);
    }

    @Override
    public Component getTableCellRendererComponent(JTable table, Object value,
                                                   boolean isSelected, boolean hasFocus, int row, int column) {
        if (isSelected) {
            setForeground(table.getSelectionForeground());
            setBackground(table.getSelectionBackground());
        } else {
            setForeground(table.getForeground());
            setBackground(table.getBackground());
        }

        setSelected((value != null && ((Boolean) value).booleanValue()));
        setFont(new Font("Arial", Font.PLAIN, 16)); // 设置字体和大小
        setHorizontalAlignment(SwingConstants.CENTER); // 设置水平居中
        setVerticalAlignment(SwingConstants.CENTER); // 设置垂直居中（如果需要）

        return this;
    }
}
